#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb

def query_data(data_counts):
    info = cur.fetchmany(data_counts)
    for li in info:
         print(li)

conn = MySQLdb.connect(host='127.0.0.1',
                       user='root',
                       passwd ='123456',
                       db='test')
cur = conn.cursor()

sql_create_table='create table student(id int,name varchar(20),class varchar(30),age varchar(10))'

sql_insert="insert into student values(2,'jack','3year2','9')"

sql_query ="select * from student"

sql_update ="update student set class='3year1' where name='Tom'"

sql_delete ="delete from student where name='Tom'"
try:
    data_counts=cur.execute(sql_query)
    print(data_counts)
    query_data(data_counts)
    print("opeart success")
    conn.commit()
except:
    print("something wrong")
    conn.rollback()
#cur.fetchone()
cur.close()
conn.close()